﻿using System;

namespace InkjetControl.codec
{
    public class Message
    {
      

        public int MagicNumber { get; set; }
        public byte MainVersion { get; set; }
        public byte ModifyVersion { get; set; }
        public byte SubVersion { get; set; }
        public long SessionId { get; set; }
        public string MachineCode { get; set; }
        public string MachineLabel { get; set; }
        public MessageType MessageType { get; set; }
        public IBody Body { get; set; }

        public Message()
        {
            MagicNumber = Constants.MAGIC_NUMBER;
            MainVersion = Constants.MAIN_VERSION;
            ModifyVersion = Constants.MODIFY_VERSION;
            SubVersion = Constants.SUB_VERSION;
            SessionId = -1;
        }
        public static Body<T> GenerateMsgBody<T>(NetCmd cmd, ref T data)
        {
            return new Body<T>(cmd, ref data);
        }

        public static Body<object> GenerateMsgBody(NetCmd cmd)
        {
            return new Body<object>(cmd);
        }
        public override string ToString()
        {
            string body = Body != null ? Body.ToString() : "";
            return string.Format("[ magicNumber: {0}, version: {1}{2}{3}, sessionID: {4}, body: {5}, MachineCode:{6}, MachineLabel: {7}]", MagicNumber, MainVersion, SubVersion, ModifyVersion, SessionId, body, MachineCode, MachineLabel);
        }
    }
}